<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文件上传</title>
</head>
<body>
    <h1>文件上传</h1>

    <form action="1.php" method="post" enctype"=mulipart/form-date" target="fm">
        <p><input type="file" name="pic" type="file"></p>
        <p><input type="submit" value="submit" name="pic"></p>

    </form>
    <script>
        var form = document.getElementsByTagName('form')[0];
        form.onsubmit = function(){
            var fmdata = new FormData(this);
            var xhr = new XMLHttpRequest();
            xhr.open('post','1.php',true);
            xhr.send(fmdata);
            xhr.onreadystatechange = function() {
                if (this.readyState == 4) {
                    alert(this.responseText);
                }
            }
        }
    </script>
</body>
</html>